/* 概率和数学期望
    概率dp E(aX+bY) = aE(X)+bE(Y)

* 本题:
    逆序拓扑
    f[i]:从i跳到N的期望长度

*/
#define DEBUG
#pragma GCC optimize("O1,O2,O3,Ofast")
#pragma GCC optimize("no-stack-protector,unroll-loops,fast-math,inline")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,ssse3")

#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define int long long
const int N = 1e5+10, M = 2e5+10;

int n, m;
int h[N], e[M], w[M], ne[M], idx;
int dout[N];
double f[N];

void AddEdge(int a, int b, int c)
{
    e[idx] = b; w[idx] = c; ne[idx] = h[a]; h[a] = idx++;
}

double dp(int u)
{
    if(f[u] >= 0) return f[u];
    f[u] = 0;
    for(int i = h[u]; ~i; i=ne[i])
    {
        int v = e[i];
        f[u] += (w[i] + dp(v)) /dout[u]; 
    }
    return f[u];
}

signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
    #else
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #endif

    cin >> n >> m;
    memset(h, -1, sizeof h);

    for(int i = 0; i < m; i++)
    {
        int a, b, c; cin >> a >> b >> c;
        AddEdge(a, b ,c);
        dout[a]++;
    }
    memset(f, -1, sizeof f);

    printf("%.2lf\n", dp(1));
    return 0;
}